﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CTManagerSoln
{
    public partial class Form1 : Form
    {// khai bao
        //khai bao chay nut duoi
        //System.Windows.Forms.Timer trmKhoiDong = new Timer();
        bool loadNutDuoi = false;
        //bien set mau cho button x
        bool isdefault = false;


        // khai bao anten quay
        System.Windows.Forms.Timer t = new Timer();
        int WIDTH = 450, HEIGHT = 450, vetquet = 225;

        int sovongtron=6;
        
        int u; //do
        int cx, cy; // tam man hinh
        int x, y; //toa do
        int tx, ty, lim = 1; // ten do hoa ; lim so duong quet
        Bitmap btm;
        Pen p;
        Graphics g;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // set mau ban dau cho nut duoi
            SetNoColor();

            // chay doi mau nut duoi
            System.Threading.Thread xanhnutduoi = new System.Threading.Thread(LoadDoWork);
            xanhnutduoi.Start();

            // radar quay
            btm = new Bitmap(WIDTH + 1, HEIGHT + 1);
            // mau xung quanh
            this.BackColor = Color.Black;
            //trung tam
            //pictureBox2.Visible;
            cx = WIDTH / 2;
            cy = HEIGHT / 2;
            //do bat dau
            u = 0;
            t.Interval = 20;
            t.Tick += new EventHandler(this.t_Tick);
            t.Start();

       
        }
        private void SetNoColor()
        {
            button1.BackColor = Color.Gray;
            button2.BackColor = Color.Gray;
            button3.BackColor = Color.Gray;



            foreach (Control ctr in panel4.Controls)
            {
                if (ctr is Label)
                {
                    Label lbl = (Label)ctr;
                    lbl.BackColor = Color.Yellow;
                }
            }
        
        }
        private void t_Tick(object sender, EventArgs e)
        {
            // vong- pen 
            p = new Pen(Color.Green, 1f);
            g = Graphics.FromImage(btm);
            // tinh toan toa do
            int tu = (u - lim) % 360;
            if (u >= 0 && u <= 180)
            {
                // chuyen do sang radian
                x = cx + (int)(vetquet * Math.Sin(Math.PI * u / 180));
                y = cy - (int)(vetquet * Math.Cos(Math.PI * u / 180));
            }
            else
            {
                x = cx - (int)(vetquet * -Math.Sin(Math.PI * u / 180));
                y = cy - (int)(vetquet * Math.Cos(Math.PI * u / 180));
            }
            if (tu >= 0 && tu <= 180)
            {
                // chuyen do sang radian
                tx = cx + (int)(vetquet * Math.Sin(Math.PI * tu / 180));
                ty = cy - (int)(vetquet * Math.Cos(Math.PI * tu / 180));
            }
            else
            {
                tx = cx - (int)(vetquet * -Math.Sin(Math.PI * tu / 180));
                ty = cy - (int)(vetquet * Math.Cos(Math.PI * tu / 180));
            }

            // ve vong tron
            /*g.DrawEllipse(p, 0, 0, WIDTH, HEIGHT); // vong tron lon nhat
            g.DrawEllipse(p, 77, 77, WIDTH - 153, HEIGHT - 153);//77,77,297,297   250
            g.DrawEllipse(p, 106, 106, WIDTH - 212, HEIGHT - 212);//106,106,238,238
            g.DrawEllipse(p, 153, 153, WIDTH - 306, HEIGHT - 306); // vong tron nho nhat*/

            for (int i = 0; i < sovongtron; i++)
            {
                g.DrawEllipse(p, i * 40 + 1, i * 40 + 1, 450 - i * 80, 450 - i * 80);
            }

            // ve duong ke
            //p.Color = Color.Red;
            Pen pnew = new Pen(Color.Red);
            g.DrawLine(pnew, new Point(cx, 0), new Point(cx, HEIGHT));
            g.DrawLine(pnew, new Point(0, cy), new Point(WIDTH, cy));
            /*g.DrawLine(pnew, new Point(cx + 120, 35), new Point(cx - 120, 415));
            g.DrawLine(pnew, new Point(cx - 120, 35), new Point(cx + 120, 415));
            g.DrawLine(pnew, new Point(cy + 360, 35), new Point(cy - 360, 415));
            g.DrawLine(pnew, new Point(cy - 360, 35), new Point(cy + 360, 415));*/
            //Width: 464,Height: 455
            g.DrawLine(pnew, new Point(cx + 120, 35), new Point(cx - 120, 415));

            //g.DrawLine(p, new Point(cx+360, 35), new Point(cx -360, 415));
            //g.DrawLine(p, new Point(cx-360, 35), new Point(cx +360, 415));
            // ve duong quet
            g.DrawLine(new Pen(Color.Black, 1f), new Point(cx, cy), new Point(tx, ty));

            g.DrawLine(p, new Point(cx, cy), new Point(x, y));

            // load bitmap len pic1
            pictureBox1.Image = btm;
            // sap xep bo tri
            p.Dispose();
            g.Dispose();
            //udate
            u++;
            if (u == 360)
            {
                u = 0;
            }
        }
        private void LoadDoWork()  // doi mau nut o duoi
        {
            try
            {
                lblKT01.BackColor = Color.Lime;
                System.Threading.Thread.Sleep(1000);
                lblKT02.BackColor = Color.Lime;
                System.Threading.Thread.Sleep(1000);
                lblKT03.BackColor = Color.Lime;
                System.Threading.Thread.Sleep(1000);
                lblKT04.BackColor = Color.Lime;
                System.Threading.Thread.Sleep(1000);
                lblKT05.BackColor = Color.Lime;
                System.Threading.Thread.Sleep(1000);
                lblKT06.BackColor = Color.Lime;
                System.Threading.Thread.Sleep(1000);
                lblKT07.BackColor = Color.Lime;
                System.Threading.Thread.Sleep(1000);
                lblKT08.BackColor = Color.Lime;
                System.Threading.Thread.Sleep(1000);
                lblKT09.BackColor = Color.Lime;
                System.Threading.Thread.Sleep(1000);
                lblKT10.BackColor = Color.Lime;
                System.Threading.Thread.Sleep(1000);
                lblKT11.BackColor = Color.Lime;
                label3.BackColor = Color.Yellow;
                label3.Text = " abcdd";
            }
            catch (Exception ex)
            {
                label13.BackColor = Color.Red;
            }
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            sovongtron = 3;
            button1.BackColor = Color.Yellow;
            button2.BackColor = Color.Green;
            button3.BackColor = Color.Gray;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            sovongtron = 6;
            button1.BackColor = Color.Gray;
            button2.BackColor = Color.Gray;
            button3.BackColor = Color.Yellow;

        }

        private void button2_Click(object sender, EventArgs e)
        {
            sovongtron = 5;
            button1.BackColor = Color.Gray;
            button2.BackColor = Color.Yellow;
            button3.BackColor = Color.Gray;
        }

        private void checkBox3_Click(object sender, EventArgs e)
        {
            if (checkBox3.Checked)
            {
                label1.BackColor = Color.Red;
                label1.Text = "aaabc";
            }
            else
            {
                label1.BackColor = Color.Gray;
                label1.Text = "san sang";
            }
              
            

            // check cai nua về trạng thái ban đầu thì làm thế nào?
        }

        private void btnX_Click(object sender, EventArgs e)
        {
            //if (isdefault)
            //{
            //    label3.BackColor = Color.Lime;
            //    label3.Text = " ВЫСОКОЕ";
            //    isdefault = true;
            //}
            //else
            //{
                label3.BackColor = Color.Lime;
                label3.Text = " ВЫСОКОЕ";
            //    isdefault = true;
            //}
            
            //label4.BackColor = Color.Lime;
            
            // click cái nữ về trạng thái ban đầu thì làm thế nào
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void btn10giay_Click(object sender, EventArgs e)
        {
            t.Interval = 10;
        }

        private void btn5giay_Click(object sender, EventArgs e)
        {
            t.Interval = 5;
        }

        private void btn2giay_Click(object sender, EventArgs e)
        {
            t.Interval = 2;
        }
    }
}
